package com.lhb.boyixue.base;

import lombok.Data;

/**
 * @author 86131
 * @version 1.0
 * @description API统一响应对象
 * @date 2025/3/30 下午8:20
 */
@Data
public class UnifyResponseObject<T> {

    private  int code;
    private String message;
    private T data;
    //成功回调
    public static <T> UnifyResponseObject<T> success(String message) {
        UnifyResponseObject<T> unifyResponseObject = new UnifyResponseObject<>();
        unifyResponseObject.setCode(1);
        unifyResponseObject.setMessage(message);
        return unifyResponseObject;
    }
    public static <T> UnifyResponseObject<T> success(T data,String message) {
        UnifyResponseObject<T> unifyResponseObject = new UnifyResponseObject<>();
        unifyResponseObject.setCode(1);
        unifyResponseObject.setData(data);
        unifyResponseObject.setMessage(message);
        return unifyResponseObject;
    }

    public static <T> UnifyResponseObject<T> success(T data) {
        UnifyResponseObject<T> unifyResponseObject = new UnifyResponseObject<>();
        unifyResponseObject.setCode(1);
        unifyResponseObject.setData(data);
        return unifyResponseObject;
    }

    //失败回调
    public static <T> UnifyResponseObject<T> fail(T data,String message,int code) {
        UnifyResponseObject<T> unifyResponseObject = new UnifyResponseObject<>();
        unifyResponseObject.setData(data);
        unifyResponseObject.setMessage(message);
        unifyResponseObject.setCode(code);
        return unifyResponseObject;
    }
    public static <T> UnifyResponseObject<T> fail(String message,int code) {
        UnifyResponseObject<T> unifyResponseObject = new UnifyResponseObject<>();
        unifyResponseObject.setMessage(message);
        unifyResponseObject.setCode(code);
        return unifyResponseObject;
    }
    public static <T> UnifyResponseObject<T> fail(String message) {
        UnifyResponseObject<T> unifyResponseObject = new UnifyResponseObject<>();
        unifyResponseObject.setMessage(message);
        unifyResponseObject.setCode(0);
        return unifyResponseObject;
    }


}
